<template>
  <div>

    <!-- 阿里云视频播放器样式 -->
    <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css" >
    <!-- 阿里云视频播放器脚本 -->
    <script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js" />

    <script src="https://g.alicdn.com/de/prismplayer/2.9.6/hls/aliplayer-vod-anti-min.js"></script>
    <!-- 定义播放器dom -->
    <div id="J_prismPlayer" class="prism-player" />
  </div>
</template>

<script>
  import {getPlayAuthv} from '~/http'
  export default {
    data(){
      return{
          secrets:"",
          vid:"",
      }
    },
    created() {
      this.getAll()

    },
    mounted() {

    },
    methods:{
      getAll(){
        if(this.$route.params.vid){
          getPlayAuthv(this.$route.params.vid).then(res=>{
            this.secrets = res.data.secret
            this.vid = this.$route.params.vid
            this.onAliplayer();
          })
        }
      },
      onAliplayer(){
        new Aliplayer({
                id: 'J_prismPlayer',
                vid: this.vid, // 视频id
                playauth: this.secrets, // 播放凭证
                encryptType: '1', // 如果播放加密视频，则需设置encryptType=1，非加密视频无需设置此项
                width: '1000px',
                height: '500px',
            }, function(player) {
                console.log('播放器创建成功')
            })
      }


    }
  }
</script>

<style scoped>
.prism-player{
  margin: auto;
}
</style>
